# -*- coding: utf-8 -*-
# @Time : 2021/5/19 14:01
# @Author : HEAD
# @Email : scg@gmail.com
# @File : tools.py
# @Project : seleniumDemo
import os
import zipfile
import shutil




def archive_test_result(filename,abs_path):
    """打包filename文件，生成一个压缩包"""
    path = os.path.join(abs_path, "report/test-result.zip")
    if os.path.exists(path):
        os.remove(path)
    zip_file = zipfile.ZipFile(path, 'w')
    # 将要压缩的文件拷贝到当前目录下
    filename = shutil.copyfile(filename, os.path.basename(filename))
    zip_file.write(filename, compress_type=zipfile.ZIP_DEFLATED)
    # 删除压缩过后的文件
    if os.path.exists(filename):
        os.remove(filename)
